package example.data;

import java.util.LinkedList;

/**
 * Created by lenovo on 2016/11/7 0007.
 * 用 top() 和 pop() 方法来获取链表的元素
 */
public class LinkElement {
    private LinkedList<Object> list = new LinkedList<>();

    private void push(Object v) {
        list.addFirst(v);
    }

    private Object top() {
        return list.getFirst();
    }

    private Object pop() {
        return list.removeFirst();
    }

    public static void main(String[] args) {
        LinkElement stack = new LinkElement();
        for (int i = 30; i < 40; i++){
            stack.push(i);
        }
        System.out.println(stack.top());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
        System.out.println(stack.pop());
    }
}
